
from datetime import timedelta, datetime
from usuaris.models import Professor
from presencia.models import Impartir


d7 = timedelta( days = -7)
d = datetime.datetime(2012, 12, 5, 16, 00,0)  #dia a repoblar

for p in Professor.objects.all():
    for i in Impartir.objects.filter(
                                     horari__professor = p, 
                                     dia_impartir = d + d7):
        i2 = Impartir.objects.filter( horari = i.horari, dia_impartir = d ).get()
        for ca in i.controlassistencia_set.all():
           ca.pk = None
           ca.estat_id = None
           ca.estat_backup_id = None
           ca.impartir = i2
           print 'de: ', i
           try:
              ca.save()
           except:
                pass



